﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimeNumbersApp
{
    class PrimeNumbers
    {
        // my own algorithm that is inspired by the solution from the net as pasted below
        // a method to validate if a given number is a prime number
        public static bool Validate(int number)
        {
            // 0 is not a prime number
            if (number <= 1)
            {
                return false;
            }

            int x = 2;
            while (x <= number/2)
            {
                if (number % x == 0)
                {
                    return false;
                }
                x++;
            }
            return true;
        }

        // a method to calculate the first 20 prime numbers
        public static void First20()
        {
            Console.WriteLine("First 20 prime numbers\n");
            int x = 1;
            int count = 1;
            while (count <= 20)
            {
                if (Validate(x))
                {

                    Console.WriteLine(count + ") "+ x);
                    count++;
                }
                x++;
            }
        }
            
        // Copied from the net http://www.authorcode.com/check-prime-number-in-net/
        public static void CheckPrimeNumber(int number)
        {
            int i;
            bool IsPrime = true;

            for (i = 2; i <= number / 2; i++)
            {
                if ((number % i == 0)) 
                {
                    IsPrime = false;
                    break; 
                }
            }

            if (IsPrime == false) 
            {
                Console.WriteLine(number + " is not a prime number");
            } 
            else
            {
                Console.WriteLine(number + " is a prime number!");
            }
        }
    }
}
